package com.tsinghuabigdata.edu.ddmath.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.tsinghuabigdata.edu.ddmath.R;


/**
 * 在线辅导-没有权限Dialog
 */
public class PermissionDialog extends Dialog implements View.OnClickListener {


    private TextView mTvTitle;
    private TextView mTvMessage;
    private Button   mBtnKnow;
    private Button   mBtnGoSetting;

    private PermissionListener mPermissionListener;


    public PermissionDialog(Context context) {
        super(context);
        initData();
    }

    public PermissionDialog(Context context, int theme) {
        super(context, theme);
        initData();
    }


    private void initData() {
        setContentView(R.layout.dialog_permission);
        mTvTitle = (TextView) findViewById(R.id.tv_title);
        mTvMessage = (TextView) findViewById(R.id.tv_message);
        mBtnKnow = (Button) findViewById(R.id.btn_know);
        mBtnGoSetting = (Button) findViewById(R.id.btn_go_setting);
        mBtnKnow.setOnClickListener(this);
        mBtnGoSetting.setOnClickListener(this);

        setCancelable(false);
        setCanceledOnTouchOutside(false);

        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.dimAmount = 0.5f;
        dialogWindow.setAttributes(lp);
        //        dialogWindow.addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
        dialogWindow.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_know:
                mPermissionListener.know();
                break;
            case R.id.btn_go_setting:
                mPermissionListener.goSetting();
                break;
        }
    }

    public interface PermissionListener {
        void know();
        void goSetting();
    }

    public void setPermissionListener(PermissionListener permissionListener) {
        mPermissionListener = permissionListener;
    }

    /**
     * 普通提示框
     */
    public void setData(String title, String message) {
        mTvTitle.setText(title);
        mTvMessage.setText(message);
    }
}
